<?php
namespace App\Logic\Amazon\AdsApi;

use App\Models\AmazonAds\AdsDailyReport;
use JetBrains\PhpStorm\NoReturn;

class ReportWork
{
    #[NoReturn] public static function exeReport(): void
    {
        //$re = self::_getReport();
        //dd($re);
        $re = self::_createReport();
        dd($re);
        $re = self::_createReportForProduct();
        dd($re);
    }
    private static function _createReportForProduct(): array
    {
        $model = AdsDailyReport::query()
            ->where('create_report_status','>',3)
            ->first();
        if(!$model){
            return ['_createReportForProduct' => date('Y-m-d H:i:s').'--无可执行数据'];
        }
        return ReportRequest::createReportForFailedAndError($model);
    }
    private static function _getReport(): array
    {
        $model = AdsDailyReport::query()
            ->where('id',10)
            ->where('create_report_status','<=',3)
            ->where('download_parse_status','<>',1)
            ->first();
        if(!$model){
            return ['_getReport' => date('Y-m-d H:i:s').'--无可执行数据'];
        }
        return ReportRequest::getReport($model);
    }

    private static function _createReport(): array
    {
//        $startDate = date('Y-m-d');
        $startDate = '2023-11-01';
//        $endDate = date('Y-m-d');
        $endDate = '2023-11-30';
        //参数里面的key不可变
        $params = [
            //'accountId' => 31,
            'SP_AP' => [
                'name' => 'SP APR '.$startDate.'~'.$endDate,
                'startDate' => $startDate,
                "endDate" => $endDate,
            ],
            'SD_AP' => [
                'name' => 'SD APR '.$startDate.'~'.$endDate,
                'startDate' => $startDate,
                "endDate" => $endDate,
            ],
            'SB_C' => [
                'name' => 'SB CR '.$startDate.'~'.$endDate,
                'startDate' => $startDate,
                'endDate' => $endDate,
            ],
            'ST_C' => [
                'name' => 'ST CR '.$startDate.'~'.$endDate,
                'startDate' => $startDate,
                'endDate' => $endDate,
            ],
        ];
        return ReportRequest::createReport($params);
    }
}
